package com.mode;

import java.util.Observable;

public class Shape extends Observable{
	
	private int[][] shape;
	private int x,y;
	
	public Shape() {

	}
	
	public void rotate(){
		for(int i=0;i<shape.length/2;i++){
			for(int j=i;j<shape.length-i-1;j++){
				int t=shape[i][j];
				shape[i][j]=shape[shape.length-j-1][i];
				shape[shape.length-j-1][i]=shape[shape.length-i-1][shape.length-j-1];
				shape[shape.length-i-1][shape.length-j-1]=shape[j][shape.length-i-1];
				shape[j][shape.length-i-1]=t;
			}
		}
		setChanged();
		notifyObservers(Shape.this);
	}
	
	public void startMove(){
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				while(true){
					moveDown();
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}).start();;
	}
	
	public void moveLeft(){
		this.x--;
		setChanged();
		notifyObservers(Shape.this);
	}
	
	public void moveDown(){
		
		if(y>20){
			y=0;
		}
		setChanged();
		notifyObservers(Shape.this);
		this.y++;
	}
	
	public void moveRight(){
		this.x++;
		setChanged();
		notifyObservers(Shape.this);
	}
	
	public int[][] getShape() {
		return shape;
	}
	
	public void setShape(int[][] shape) {
		this.shape = shape;
	}
	
	public int getX() {
		return x;
	}
	
	public int getY() {
		return y;
	}
}
